package com.service.bank.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.client.model.pojo.bank.Deposit;
import com.client.model.pojo.bank.DepositRecord;
import com.client.model.vo.common.Result;
import com.service.bank.mapper.DepositMapper;
import com.service.bank.service.DepositRecordService;
import com.service.bank.mapper.DepositRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author liuwenju
* @description 针对表【deposit_record】的数据库操作Service实现
* @createDate 2024-04-06 17:24:36
*/
@Service
public class DepositRecordServiceImpl extends ServiceImpl<DepositRecordMapper, DepositRecord>
    implements DepositRecordService{

    @Autowired
    private DepositRecordMapper depositRecordMapper;

    @Autowired
    private DepositMapper depositMapper;

    @Override
    public Result refuse(Long id) {
        DepositRecord optById = depositRecordMapper.selectById(id);
        //将转款金额退回到原有账户
        Deposit deposit = depositMapper.selectOne(new QueryWrapper<Deposit>()
                .eq("bank_card", optById.getBankCard())
                .eq("id", optById.getRemark()));
        deposit.setBalance(deposit.getBalance().add(optById.getBalance()));
        depositMapper.updateById(deposit);
        //修改申请管理的状态
        optById.setStatus(2);
        depositRecordMapper.updateById(optById);
        return  Result.build(null,200,"取消成功");
    }
}




